﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ict.DataAccess.Conditions
{
    /// <summary>
    /// 关系表达式条件，用于表示字段值和数值之间的相等、不等、小于、大于
    /// </summary>
    [Serializable]
    public class RelationCond : Condition
    {
        /// <summary>
        /// 定义关系运算符的枚举
        /// </summary>
        public enum RelationOperator
        {
            /// <summary>
            /// 等于
            /// </summary>
            Equal, 
            /// <summary>
            /// 不等于
            /// </summary>
            Notequal,
            /// <summary>
            /// 小于
            /// </summary>
            Less,
            /// <summary>
            /// 大于
            /// </summary>
            Greater,
            /// <summary>
            /// 小于等于
            /// </summary>
            LessEqual,
            /// <summary>
            /// 大于等于
            /// </summary>
            GreaterEqual
        }

        private RelationOperator _operator = RelationOperator.Equal;
        /// <summary>
        /// 获取关系运算符
        /// </summary>
        public RelationOperator Operator
        {
            get
            {
                return _operator;
            }
        }

        private string _fieldName = null;
        /// <summary>
        /// 获取字段名
        /// </summary>
        public string FieldName
        {
            get
            {
                return _fieldName;
            }
        }

        private object _fieldValue = null;
        /// <summary>
        /// 获取字段值
        /// </summary>
        public object FieldValue
        {
            get
            {
                return _fieldValue;
            }
        }

        /// <summary>
        /// 生成相等关系的条件
        /// </summary>
        /// <param name="fieldName">字段名</param>
        /// <param name="fieldValue">字段值</param>
        public RelationCond(string fieldName, object fieldValue)
        {
            _fieldName = fieldName;
            _fieldValue = fieldValue;
        }

        /// <summary>
        /// 生成任意关系条件
        /// </summary>
        /// <param name="fieldName">字段名</param>
        /// <param name="fieldValue">字段值</param>
        /// <param name="op">运算符</param>
        public RelationCond(string fieldName, object fieldValue, RelationOperator op)
        {
            _fieldName = fieldName;
            _fieldValue = fieldValue;
            _operator = op;
        }
    }
}
